package org.jeecgframework.web.service.impl;

import org.jeecgframework.core.common.exception.BusinessException;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.constant.Globals;
import org.jeecgframework.core.util.ResourceUtil;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.core.util.oConvertUtils;
import org.jeecgframework.web.service.CbsInspectionEvaluateServiceI;
import org.jeecgframework.web.service.CbsLightReportServiceI;
import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import org.jeecgframework.web.service.CbsServiceLogServiceI;
import org.jeecgframework.web.service.CbsServiceReportServiceI;
import org.jeecgframework.web.system.pojo.base.*;
import org.jeecgframework.web.system.service.SystemService;
import org.jeecgframework.web.util.FileBean;
import org.jeecgframework.web.util.SendMailUtil;
import org.jeecgframework.web.util.StaticValue;
import org.jeecgframework.web.util.UploadFileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.Serializable;

@Service("cbsLightReportService")
@Transactional
public class CbsLightReportServiceImpl extends CommonServiceImpl implements CbsLightReportServiceI {

    @Autowired
    private CbsInspectionEvaluateServiceI cbsInspectionEvaluateService;
    @Autowired
    private CbsServiceLogServiceI cbsServiceLogServiceI;
    @Autowired
    private CbsServiceReportServiceI cbsServiceReportService;
    @Autowired
    SystemService systemService;

    public <T> void delete(T entity) {
        super.delete(entity);
        //执行删除操作配置的sql增强
        this.doDelSql((CbsLightReportEntity) entity);
    }

    public <T> Serializable save(T entity) {
        Serializable t = super.save(entity);
        //执行新增操作配置的sql增强
        this.doAddSql((CbsLightReportEntity) entity);
        return t;
    }

    public <T> void saveOrUpdate(T entity) {
        super.saveOrUpdate(entity);
        //执行更新操作配置的sql增强
        this.doUpdateSql((CbsLightReportEntity) entity);
    }

    /**
     * 默认按钮-sql增强-新增操作
     *
     * @param id
     * @return
     */
    public boolean doAddSql(CbsLightReportEntity t) {
        return true;
    }

    /**
     * 默认按钮-sql增强-更新操作
     *
     * @param id
     * @return
     */
    public boolean doUpdateSql(CbsLightReportEntity t) {
        return true;
    }

    /**
     * 默认按钮-sql增强-删除操作
     *
     * @param id
     * @return
     */
    public boolean doDelSql(CbsLightReportEntity t) {
        return true;
    }

    /**
     * 替换sql中的变量
     *
     * @param sql
     * @return
     */
    public String replaceVal(String sql, CbsLightReportEntity t) {
        sql = sql.replace("#{id}", String.valueOf(t.getId()));
        sql = sql.replace("#{report_category}", String.valueOf(t.getReportCategory()));
        sql = sql.replace("#{service_id}", String.valueOf(t.getServiceId()));
        sql = sql.replace("#{scene_total}", String.valueOf(t.getSceneTotal()));
        sql = sql.replace("#{finish_file}", String.valueOf(t.getFinishFile()));
        sql = sql.replace("#{photo_file}", String.valueOf(t.getPhotoFile()));
        sql = sql.replace("#{photo_type}", String.valueOf(t.getPhotoType()));
        sql = sql.replace("#{is_error}", String.valueOf(t.getIsError()));
        sql = sql.replace("#{is_complete}", String.valueOf(t.getIsComplete()));
        sql = sql.replace("#{yc_des}", String.valueOf(t.getYcDes()));
        sql = sql.replace("#{front_sn}", String.valueOf(t.getFrontSn()));
        sql = sql.replace("#{front_ldfl}", String.valueOf(t.getFrontLdfl()));
        sql = sql.replace("#{front_dbd}", String.valueOf(t.getFrontDbd()));
        sql = sql.replace("#{front_jyx}", String.valueOf(t.getFrontJyx()));
        sql = sql.replace("#{after_sn}", String.valueOf(t.getAfterSn()));
        sql = sql.replace("#{after_ldfl}", String.valueOf(t.getAfterLdfl()));
        sql = sql.replace("#{after_dbd}", String.valueOf(t.getAfterDbd()));
        sql = sql.replace("#{after_jyx}", String.valueOf(t.getAfterJyx()));
        sql = sql.replace("#{hjgld}", String.valueOf(t.getHjgld()));
        sql = sql.replace("#{lt}", String.valueOf(t.getLlt()));
        sql = sql.replace("#{ct}", String.valueOf(t.getCt()));
        sql = sql.replace("#{rt}", String.valueOf(t.getRt()));
        sql = sql.replace("#{lc}", String.valueOf(t.getLc()));
        sql = sql.replace("#{cc}", String.valueOf(t.getCc()));
        sql = sql.replace("#{rc}", String.valueOf(t.getRc()));
        sql = sql.replace("#{lb}", String.valueOf(t.getLb()));
        sql = sql.replace("#{cb}", String.valueOf(t.getCb()));
        sql = sql.replace("#{rb}", String.valueOf(t.getRb()));
        sql = sql.replace("#{run_des}", String.valueOf(t.getRunDes()));
        sql = sql.replace("#{status}", String.valueOf(t.getStatus()));
        sql = sql.replace("#{create_name}", String.valueOf(t.getCreateName()));
        sql = sql.replace("#{create_by}", String.valueOf(t.getCreateBy()));
        sql = sql.replace("#{create_date}", String.valueOf(t.getCreateDate()));
        sql = sql.replace("#{update_name}", String.valueOf(t.getUpdateName()));
        sql = sql.replace("#{update_by}", String.valueOf(t.getUpdateBy()));
        sql = sql.replace("#{update_date}", String.valueOf(t.getUpdateDate()));
        sql = sql.replace("#{UUID}", UUID.randomUUID().toString());
        return sql;
    }


    public Map<String, Object> photoFileUploadView(HttpServletRequest request, String serviceId, String businessType, String photoName) {
        Map<String, Object> attributes = new HashMap<String, Object>();

        String oldPhotoName = "";
        //获取本服务单已上传的完工单照片
        String sql = "SELECT new_file_name FROM `zy_file_log` WHERE business_key='" + serviceId + "' AND business_type='I' AND business_child_type='IP' AND new_file_name LIKE '%" + photoName + "%' ORDER BY new_file_name DESC";
        List<Map<String, Object>> photoFileList = super.findForJdbc(sql);
        if (photoFileList != null) {
            if (photoFileList.size() == 0) {
                oldPhotoName = photoName;
            }
            if (photoFileList.size() > 0) {
                String str = (String) photoFileList.get(0).get("new_file_name");
                if (StringUtil.isNotEmpty(str)) {
                    String numStr = str.replaceAll(photoName, "");
                    if (StringUtil.isNotEmpty(numStr)) {
                        int pNum = Integer.valueOf(numStr);
                        String num = pNum + 1 + "";
                        oldPhotoName = photoName + num;
                    } else {
                        String num = photoFileList.size() + "";
                        oldPhotoName = photoName + num;
                    }
                }
            }
        }
        if (serviceId != null && serviceId != "") {
            FileBean fileBean = UploadFileUtil.UploadFile(request);
            if (StringUtil.isNotEmpty(serviceId)) {
                ZyFileLogEntity zyfileLog = new ZyFileLogEntity();
                zyfileLog.setBusinessKey(serviceId);
                zyfileLog.setFilePath(fileBean.getSavePath());
                zyfileLog.setOldFileName(fileBean.getFileRealName());
                zyfileLog.setNewFileName(oldPhotoName);
                zyfileLog.setCreateDate(new Date());
                zyfileLog.setCreateDate(new Date());
                zyfileLog.setBusinessType("I");
                zyfileLog.setBusinessChildType("IP");
                zyfileLog.setFileType("wgd");
                super.save(zyfileLog);
                attributes.put("name", zyfileLog.getNewFileName());
            }
            String id = null;
            Map<String, Object> fileLogMap = super.findOneForJdbc("SELECT t.id FROM zy_file_log t where  t.business_key = '" + serviceId + "' and old_file_name = '" + fileBean.getFileRealName() + "'order by t.create_date desc limit 1 ");
            if (fileLogMap != null) {
                id = fileLogMap.get("id").toString();
            }
            attributes.put("id", id);
        }

        return attributes;
    }

    @Override
    public AjaxJson ZCLightReport(HttpServletRequest request) {
        AjaxJson j = new AjaxJson();
        boolean flag = true;
        String message = "光管翻新验收单暂存成功";
        try {
            CbsLightReportEntity lightReport = null;
            CbsServiceEntity service = null;
            TSTerritory sheng = null;
            TSTerritory shi = null;
            ZyFileLogEntity finishFile = null;
            ZyFileLogEntity photo = null;
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
            String orderTimeStr = request.getParameter("orderTime");
            String actualTimeStr = request.getParameter("actualTime");
            String finishTimeStr = request.getParameter("closeTime");
            String serviceId = request.getParameter("serviceId");

            if (serviceId != null && serviceId != "") {
                service = systemService.get(CbsServiceEntity.class, serviceId);
                lightReport = systemService.singleResult("from CbsLightReportEntity where serviceId.id='" + serviceId + "'");
            }

            if (StringUtil.isNotEmpty(service) && !service.getSpeedStatus().equals("7")) {
                if (lightReport == null) {
                    lightReport = new CbsLightReportEntity();
                    lightReport.setReportCategory(6);
                    lightReport.setStatus("1");
                    lightReport.setServiceId(service);
                }
                String shengCode = request.getParameter("province");
                if (shengCode != null && shengCode != "") {
                    sheng = systemService.singleResult("from TSTerritory where territoryLevel = 1 and territoryCode='" + shengCode + "'");
                }

                String shiCode = request.getParameter("city");
                if (shiCode != null && shiCode != "") {
                    shi = systemService.singleResult("from TSTerritory where territoryLevel = 2 and territoryCode='" + shiCode + "'");
                }

                String finishFileId = request.getParameter("finishFileId");
                if (finishFileId != null && finishFileId != "") {
                    finishFile = systemService.get(ZyFileLogEntity.class, finishFileId);
                    lightReport.setFinishFile(finishFile);
                }

                String photoId = request.getParameter("photoId");
                if (photoId != null && photoId != "") {
                    photo = systemService.get(ZyFileLogEntity.class, photoId);
                    lightReport.setPhotoFile(photo);
                }
                //基本信息
                if (orderTimeStr != null && orderTimeStr != "") {
                    lightReport.setOrderTime(sdf1.parse(orderTimeStr));
                }
                if (actualTimeStr != null && actualTimeStr != "") {
                    lightReport.setActualTime(sdf.parse(actualTimeStr));
                }
                if (finishTimeStr != null && finishTimeStr != "") {
                    lightReport.setFinishTime(sdf.parse(finishTimeStr));
                }
                if (StringUtil.isNotEmpty(request.getParameter("esTypeId"))) {
                    ZyEquipmentTypeEntity type = systemService.get(ZyEquipmentTypeEntity.class, request.getParameter("esTypeId"));
                    lightReport.setEquipmentType(type);
                }
                lightReport.setCinemaName(request.getParameter("zyCinemaName"));
                lightReport.setSceneTotal(request.getParameter("sceneTotal"));
                lightReport.setSheng(sheng);
                lightReport.setShi(shi);
                lightReport.setAddress(request.getParameter("address"));
                lightReport.setTypeIntherterName(request.getParameter("typename"));
                lightReport.setContactsName(request.getParameter("contactsName"));
                lightReport.setPhone(request.getParameter("phone"));
                lightReport.setSn(request.getParameter("sn"));
                lightReport.setPhotoType(request.getParameter("photoType"));//现场信息
                if (request.getParameter("isBad") != null && !request.getParameter("isBad").equals("")) {//翻新光管外观检查
                    lightReport.setIsError(Integer.valueOf(request.getParameter("isBad")));
                }
                if (request.getParameter("isComplete") != null && !request.getParameter("isComplete").equals("")) {
                    lightReport.setIsComplete(Integer.valueOf(request.getParameter("isComplete")));
                }
                lightReport.setYcDes(request.getParameter("errorDes"));
                lightReport.setFrontSn(request.getParameter("front_sn"));//测试数据
                lightReport.setFrontLdfl(request.getParameter("front_ldfl"));
                lightReport.setFrontDbd(request.getParameter("front_dbd"));
                lightReport.setFrontJyx(request.getParameter("front_jyx"));
                lightReport.setAfterSn(request.getParameter("after_sn"));
                lightReport.setAfterLdfl(request.getParameter("after_ldfl"));
                lightReport.setAfterDbd(request.getParameter("after_dbd"));
                lightReport.setAfterJyx(request.getParameter("after_jyx"));
                lightReport.setHjgld(request.getParameter("hjgld"));
                lightReport.setLlt(request.getParameter("lt"));//画面检查
                lightReport.setCt(request.getParameter("ct"));
                lightReport.setRt(request.getParameter("rt"));
                lightReport.setLc(request.getParameter("lc"));
                lightReport.setCc(request.getParameter("cc"));
                lightReport.setRc(request.getParameter("rc"));
                lightReport.setLb(request.getParameter("lb"));
                lightReport.setCb(request.getParameter("cb"));
                lightReport.setRb(request.getParameter("rb"));
                //放映机运行检查
                lightReport.setRunDes(request.getParameter("run_des"));
                systemService.saveOrUpdate(lightReport);
            } else {
                flag = false;
                message = "光管翻新验收单暂存成功，请刷新页面！";
            }
        } catch (Exception e) {
            message = "光管翻新验收单暂存失败";
            flag = false;
            e.printStackTrace();
            System.err.println("事务出现异常,回滚事务！");
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//此处采用手动回滚
        }
        j.setMsg(message);
        j.setSuccess(flag);
        return j;
    }

    @Override
    public AjaxJson subLightReport(HttpServletRequest request) {
        AjaxJson j = new AjaxJson();
        boolean flag = true;
        String message = "光管翻新验收单提交成功";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        String types = request.getParameter("type");
        String serviceId = request.getParameter("serviceId");
        String orderTimeStr = request.getParameter("orderTime");
        String actualTimeStr = request.getParameter("actualTime");
        String finishTimeStr = request.getParameter("closeTime");
        String esTypeId = request.getParameter("esTypeId");
        String photoType = request.getParameter("photoType");
        String isBad = request.getParameter("isBad");
        String isComplete = request.getParameter("isComplete");
        String errorDes = request.getParameter("errorDes");
        String front_sn = request.getParameter("front_sn");
        String front_ldfl = request.getParameter("front_ldfl");
        String front_dbd = request.getParameter("front_dbd");
        String front_jyx = request.getParameter("front_jyx");
        String after_sn = request.getParameter("after_sn");
        String after_ldfl = request.getParameter("after_ldfl");
        String after_dbd = request.getParameter("after_dbd");
        String after_jyx = request.getParameter("after_jyx");
        String hjgld = request.getParameter("hjgld");

        //是否为补填完工单
        Boolean editReport = Boolean.valueOf(oConvertUtils.getString(request.getParameter("editReport")));

        CbsLightReportEntity lightReport = null;
        CbsServiceEntity service = null;
        TSTerritory sheng = null;
        TSTerritory shi = null;
        ZyFileLogEntity finishFile = null;
        ZyFileLogEntity photo = null;
        try {
            if (StringUtil.isNotEmpty(serviceId)) {
                service = systemService.get(CbsServiceEntity.class, serviceId);
                //如果是补填完工单 或者 状态不是7
                if (editReport || !service.getSpeedStatus().equals("7")) {
                    if(!editReport){//如果不是补填完工单 则更新状态防止修改原状态
                        systemService.updateBySqlString("update cbs_service set speed_status='" + StaticValue.fwywc + "' where id='" + serviceId + "'");
                    }
                    lightReport = systemService.singleResult("from CbsLightReportEntity where serviceId.id='" + serviceId + "'");
                    if (lightReport == null) {
                        lightReport = new CbsLightReportEntity();
                        lightReport.setReportCategory(6);
                        lightReport.setStatus("1");
                        lightReport.setServiceId(service);
                    }
                    String shengCode = request.getParameter("province");
                    if (shengCode != null && shengCode != "") {
                        sheng = this.singleResult("from TSTerritory where territoryCode='" + shengCode + "'");
                    }
                    String shiCode = request.getParameter("city");
                    if (shiCode != null && shiCode != "") {
                        shi = this.singleResult("from TSTerritory where territoryCode='" + shiCode + "'");
                    }
                    String finishFileId = request.getParameter("finishFileId");
                    if (finishFileId != null && finishFileId != "") {
                        finishFile = this.get(ZyFileLogEntity.class, finishFileId);
                        lightReport.setFinishFile(finishFile);
                    }
                    String photoId = request.getParameter("photoId");
                    if (photoId != null && photoId != "") {
                        photo = this.get(ZyFileLogEntity.class, photoId);
                        lightReport.setPhotoFile(photo);
                    }
                    //基本信息
                    if (orderTimeStr != null && orderTimeStr != "") {
                        lightReport.setOrderTime(sdf.parse(orderTimeStr));
                    }
                    if (actualTimeStr != null && actualTimeStr != "") {
                        lightReport.setActualTime(sdf.parse(actualTimeStr));
                    }
                    if (finishTimeStr != null && finishTimeStr != "") {
                        lightReport.setFinishTime(sdf.parse(finishTimeStr));
                    }

                    if (StringUtil.isNotEmpty(esTypeId)) {
                        ZyEquipmentTypeEntity type = this.get(ZyEquipmentTypeEntity.class, esTypeId);
                        lightReport.setEquipmentType(type);
                    }
                    //现场信息
                    if (StringUtil.isNotEmpty(photoType)) {
                        lightReport.setPhotoType(photoType);
                    }
                    //翻新光管外观检查
                    if (StringUtil.isNotEmpty(isBad)) {
                        lightReport.setIsError(Integer.valueOf(isBad));
                    }
                    if (StringUtil.isNotEmpty(isComplete)) {
                        lightReport.setIsComplete(Integer.valueOf(isComplete));
                    }
                    lightReport.setCinemaName(request.getParameter("zyCinemaName"));
                    lightReport.setSceneTotal(request.getParameter("sceneTotal"));
                    lightReport.setSheng(sheng);
                    lightReport.setShi(shi);
                    lightReport.setAddress(request.getParameter("address"));
                    lightReport.setTypeIntherterName(request.getParameter("typename"));
                    lightReport.setContactsName(request.getParameter("contactsName"));
                    lightReport.setPhone(request.getParameter("phone"));
                    lightReport.setSn(request.getParameter("sn"));
                    lightReport.setYcDes(StringUtil.isNotEmpty(errorDes) ? errorDes : "");
                    lightReport.setFrontSn(StringUtil.isNotEmpty(front_sn) ? front_sn : "");
                    lightReport.setFrontLdfl(StringUtil.isNotEmpty(front_ldfl) ? front_ldfl : "");
                    lightReport.setFrontDbd(StringUtil.isNotEmpty(front_dbd) ? front_dbd : "");
                    lightReport.setFrontJyx(StringUtil.isNotEmpty(front_jyx) ? front_jyx : "");
                    lightReport.setAfterSn(StringUtil.isNotEmpty(after_sn) ? after_sn : "");
                    lightReport.setAfterLdfl(StringUtil.isNotEmpty(after_ldfl) ? after_ldfl : "");
                    lightReport.setAfterDbd(StringUtil.isNotEmpty(after_dbd) ? after_dbd : "");
                    lightReport.setAfterJyx(StringUtil.isNotEmpty(after_jyx) ? after_jyx : "");
                    lightReport.setHjgld(StringUtil.isNotEmpty(hjgld) ? hjgld : "");
                    //画面检查
                    lightReport.setLlt(request.getParameter("lt"));
                    lightReport.setCt(request.getParameter("ct"));
                    lightReport.setRt(request.getParameter("rt"));
                    lightReport.setLc(request.getParameter("lc"));
                    lightReport.setCc(request.getParameter("cc"));
                    lightReport.setRc(request.getParameter("rc"));
                    lightReport.setLb(request.getParameter("lb"));
                    lightReport.setCb(request.getParameter("cb"));
                    lightReport.setRb(request.getParameter("rb"));
                    //放映机运行检查
                    lightReport.setRunDes(request.getParameter("run_des"));
                    this.saveOrUpdate(lightReport);

                    //非 补填完工单时进行 以下关于服务单的操作
                    if(!editReport){
                        service.setSpeedStatus("7");
                        service.setReportId(lightReport.getId());
                        service.setReportType(5);

                        if (types.equals("2")) { //HD提交的完工任务
                            service.setStatus("4");
                            service.setCloseTime(new Date());
                        } else {
                            if (service.getHdClose() != null && service.getHdClose() == 1) {

                                //邮件提醒HD进行检查和关单操作
                                String FWS = "";
                                String serviceType = "";
                                if (service != null) {
                                    if (service.getServiceType2() != null) {
                                        serviceType = service.getServiceType2().getName();
                                    }

                                    if (StringUtil.isNotEmpty(service.getServiceProviderCode())) {
                                        TSDepart FWSTs = this.singleResult("from TSDepart where orgCode='" + service.getServiceProviderCode() + "'");
                                        if (FWSTs != null) {
                                            FWS = FWSTs.getDepartname();
                                        }
                                    }
                                }

                                String enginnerName = "";
                                String enginnerPhone = "";
                                if (StringUtil.isNotEmpty(service.getEngineer())) {
                                    ZyEngineerEntity enginner = this.get(ZyEngineerEntity.class, service.getEngineer());
                                    if (enginner != null) {
                                        enginnerName = enginner.getName();
                                        enginnerPhone = enginner.getCellphone();
                                    }
                                }
                                String mailTital = "服务单手动关单通知：<" + FWS + ">-<" + service.getLevel() + ">-<" + serviceType + ">-<" + service.getCode() + ">-<" + service.getZyCinemaName() + ">-" + getDateStr(new Date());
                                String mailContent = "服务单号<" + service.getCode() + ">已完工，需要您审核后手动进行关单操作。如有疑问请联系现场工程师：<" + enginnerName + "><" + enginnerPhone + ">\n" +
                                        "具体内容请查看http://cbs.cfg-barco.com或登陆巴可客服App。\n" +
                                        "【中影巴可客服部】\n" +
                                        "* 该邮件请勿回复";
                                List<TSUser> HDUserList = new ArrayList<>();
                                List<TSRoleUser> tsRoleUserList = this.findHql("from TSRoleUser where TSRole.roleCode='" + StaticValue.CBS_HD_ROLE_CODE + "'");
                                for (TSRoleUser tsRoleUser : tsRoleUserList) {
                                    if (StringUtil.isNotEmpty(tsRoleUser.getTSUser()) && StringUtil.isNotEmpty(tsRoleUser.getTSUser().getStatus()) && tsRoleUser.getTSUser().getStatus().equals(Globals.User_Normal)) { //正常状态的用户
                                        TSUser HDUser = tsRoleUser.getTSUser();
                                        HDUserList.add(HDUser);
                                    }

                                }
                                if (HDUserList.size() > 0) {
                                    for (TSUser HDUser : HDUserList) {
                                        if (StringUtil.isNotEmpty(HDUser.getEmail())) {
                                            SendMailUtil.sendeMail(HDUser.getEmail(), mailTital, mailContent, systemService);
                                        }
                                    }
                                }
                            } else {
                                service.setStatus("4");
                                service.setCloseTime(new Date());
                            }
                        }

                        systemService.saveOrUpdate(service);
                        //判断服务单完工时，是否需要自动创建回访
                        cbsInspectionEvaluateService.assessService(service.getId());
                    }

                    //完工报告提交成功，添加日志
                    TSUser tsUser = ResourceUtil.getSessionUserName();
                    if(editReport){
                        cbsServiceLogServiceI.addServiceLog(service, StaticValue.Close_Service_Log_Type_2, tsUser.getRealName() + "补填了完工单。", null);
                    } else if (types.equals("2")) {
                        cbsServiceLogServiceI.addServiceLog(service, StaticValue.Close_Service_Log_Type_2, tsUser.getRealName() + "提交了完工报告，并且关闭了服务单。", null);
                    } else {
                        cbsServiceLogServiceI.addServiceLog(service, StaticValue.Close_Service_Log_Type_2, tsUser.getRealName() + "提交了完工报告。", null);
                    }
                    systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);

                } else {
                    flag = false;
                    message = "服务单第三方已完成，请刷新页面！";
                }
            }
        } catch (Exception e) {
            message = "保存异常";
            flag = false;
            e.printStackTrace();
            System.err.println("事务出现异常,回滚事务！");
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//此处采用手动回滚
        }
        j.setMsg(message);
        j.setSuccess(flag);
        return j;
    }

    //当前日期转化为MMdd字符转
    public String getDateStr(Date date) {
        SimpleDateFormat df = new SimpleDateFormat("MMdd");
        String dateStr = df.format(date);
        return dateStr;
    }

}